local genpi = fk.CreateSkill {
  name = "th_genpi",
}

genpi:addEffect(fk.Damaged, {
  anim_type = "control",
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = player:getHandcardNum() + player:getLostHp()
    local targets = table.filter(room:getOtherPlayers(player, false), function(p)
      return p:getHandcardNum() <= n
    end)
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#th_genpi-invoke:::" .. n,
      skill_name = genpi.name
    })
    if #to == 1 then
      event:setCostData(self, { tos = to })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local to = dat.tos[1]
    room:swapCards(player, {
      {player, player:getCardIds("h")},
      {to, to:getCardIds("h")},
    },
    genpi.name)
  end
})

Fk:loadTranslationTable{
  ["th_genpi"] = "更裨",
  [":th_genpi"] = "当你受到伤害后，你可以与一名手牌数不大于X的其他角色交换手牌（X为你的手牌数+你已损失的体力值）。",

  ["#th_genpi-invoke"] = "更裨：你可以与一名手牌数不大于 %arg 的其他角色交换手牌",
}

return genpi